import request from '@/utils/request'
import { BaseResponse } from '@/types/api'

// 登录相关接口类型定义
export interface LoginParams {
  username: string;
  password: string;
  code?: string;
}

export interface LoginResult {
  token: string;
}

/**
 * 用户登录
 * @param data 登录参数
 */
export function login(data: LoginParams): Promise<BaseResponse<LoginResult>> {
  return request({
    url: '/base/login',
    method: 'post',
    data
  })
}

/**
 * 刷新 token
 */
export function refreshToken(): Promise<BaseResponse<{token: string}>> {
  return request({
    url: '/base/refreshToken',
    method: 'post'
  })
}

/**
 * 退出登录
 */
export function logout(): Promise<BaseResponse> {
  return request({
    url: '/base/logout',
    method: 'post'
  })
}
